package dao;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

import javax.swing.tree.RowMapper;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import common.CommException;
import common.JdbcUtils;
import domain.User;

public class LoginDao {
    private  Logger logger =LoggerFactory.getLogger(getClass());
    
	public User findlogin(String usercode) {
		Connection conn = JdbcUtils.getConnection();
		PreparedStatement ps =null;
		ResultSet rs =null;
		try {
			 String sql = "select* from user where usercode =?";
			 ps=conn.prepareStatement(sql);
			 ps.setString(1, usercode);
			 logger.debug(sql);
			 
			 rs=ps.executeQuery();
			 while(rs.next()) {
				 
				 return rowMap(rs); 
						 
			 }
		} catch (Exception e) {
		  logger.error(e.getMessage());
		  throw new CommException();
			
		}finally {
			JdbcUtils.close(conn, ps, rs);
		}
		return null;
	}

	private User rowMap(ResultSet rs) throws SQLException {
		User user = new User();
	    user.setId(rs.getInt("id"));
		user.setPasswords(rs.getString("passwords"));
		user.setUsercode(rs.getString("usercode"));
		return null;
	}

}
